using MediatR;
using Medical.Api.Write.Application.Command.Wms.WmsLssueCommand;
using Medical.ErrorCode;
using Medical.Api.Write.Service.WmsService;
using System.Threading;
using System.Threading.Tasks;

namespace Medical.Api.Write.Application.Handler.Wms.WmsLssueHandler
{
    /// <summary>
    /// 根据出库单主键Id新增发放单处理器
    /// </summary>
    /// <remarks>
    /// 1. 接收AddLssueFromOutCommand命令
    /// 2. 调用Service层AddLssueFromOutAsync方法，完成业务逻辑
    /// 3. 返回ApiResult<bool>结果
    /// </remarks>
    public class AddLssueFromOutHandler : IRequestHandler<AddLssueFromOutCommand, ApiResult<bool>>
    {
        private readonly IWmsService _service;
        /// <summary>
        /// 构造函数，注入WmsService
        /// </summary>
        /// <param name="service">WmsService服务</param>
        public AddLssueFromOutHandler(IWmsService service) { _service = service; }
        /// <summary>
        /// 处理新增发放单命令，调用Service层实现
        /// </summary>
        /// <param name="request">命令参数</param>
        /// <param name="cancellationToken">取消令牌</param>
        /// <returns>ApiResult结果</returns>
        public async Task<ApiResult<bool>> Handle(AddLssueFromOutCommand request, CancellationToken cancellationToken)
        {
            return await _service.AddLssueFromOutAsync(request);
        }
    }
}